package dhee.wtqshopproject.dao;


import dhee.wtqshopproject.entity.User;
import org.apache.ibatis.jdbc.SQL;

public class UserSqlProvider {

    //注册  必须填的字段username和password  phone后期的 用于手机登录
    public String insertUserSql(User user) {
        return new SQL() {{
            INSERT_INTO("hxshop.user");
            // 必填字段
            VALUES("username", "#{username}");
            VALUES("phone", "#{phone}");
            VALUES("password", "#{password}");
            // 可选字段
            if (user.getSex() != null) {
                VALUES("sex", "#{sex}");
            }
            if (user.getEmail() != null) {
                VALUES("email", "#{email}");
            }
            if (user.getAvatarUrl() != null) {
                VALUES("avatar_url", "#{avatarUrl}");
            }
            if (user.getCreateTime() != null) {
                VALUES("create_time", "#{createTime}");
            }
            if (user.getRole() != null) {
                VALUES("role", "#{role}");
            }
                VALUES("is_active", "1");
        }}.toString();
    }

    //登录
    public String LoginSql(User user) {
        return new SQL() {{
            SELECT("*");
            FROM("user");
            WHERE("username = #{username}");
            WHERE("password = #{password}");
            WHERE("is_active = 1");//用户状态在活动中返回用户
        }}.toString();
    }
}
